Skip to content

Feat: Add unit tests for ToggleDarkMode component#737

Open
kartikrautan wants to merge 4 commits intoaccordproject:mainfrom
kartikrautan:unitTest
Open

Feat: Add unit tests for ToggleDarkMode component#737
kartikrautan wants to merge 4 commits intoaccordproject:mainfrom
kartikrautan:unitTest

Conversation

@kartikrautan
Copy link
Contributor

@kartikrautan kartikrautan commented Feb 23, 2026

Add Unit Tests for ToggleDarkMode Component

Closes #728

Adds a comprehensive unit test suite for the ToggleDarkMode component using Vitest and React Testing Library, following the same mocking and testing patterns established in existing test files (SettingsModal.test.tsx, PlaygroundSidebar.test.tsx).


Changes

  • Added src/tests/components/ToggleDarkMode.test.tsx with 10 unit tests
  • Tests cover:
    • Component rendering
    • Light/dark mode initialization
    • Store integration (toggleDarkMode call verification)
    • data-theme DOM attribute updates
    • useEffect re-render on backgroundColor change
    • Prop forwarding (size={60}, className)
    • Sequential toggle behavior
  • Mocked:
    • ../../store/store
    • react-dark-mode-toggle
    • ../../styles/components/ToggleDarkMode
    • (Following existing project testing patterns)
  • All 54 tests pass (44 existing + 10 new)

Flags

  • No changes to source code — this PR only adds tests
  • The store mock supports both selector and no-selector useAppStore() call patterns

Screenshots or Video

Screenshot 2026-02-23 152156

Related Issues

  • Issue #
  • Pull Request #

Author Checklist

  • Ensure you provide a DCO sign-off for your commits using the --signoff option of git commit
  • Vital features and changes captured in unit and/or integration tests
  • Commit messages follow AP format
  • Extend the documentation, if necessary
  • Merging to main from fork:branchname

@kartikrautan kartikrautan requested a review from a team as a code owner February 23, 2026 09:58
@netlify
Copy link

netlify bot commented Feb 23, 2026

Deploy Preview for ap-template-playground ready!

Name Link
🔨 Latest commit 8cb52cf
🔍 Latest deploy log https://app.netlify.com/projects/ap-template-playground/deploys/69a8020ba4a1c90008556ab9
😎 Deploy Preview https://deploy-preview-737--ap-template-playground.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@kartikrautan kartikrautan changed the title Add unit tests for ToggleDarkMode component Feat: Add unit tests for ToggleDarkMode component Feb 23, 2026
@mttrbrts mttrbrts closed this Feb 24, 2026
@mttrbrts mttrbrts reopened this Feb 24, 2026
@mttrbrts
Copy link
Member

@copilot please review this pull request

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds comprehensive unit test coverage for the ToggleDarkMode component, addressing Issue #728. The PR introduces 10 well-structured test cases using Vitest and React Testing Library, following established testing patterns in the codebase. The tests verify component rendering, state initialization, store integration, DOM updates, prop forwarding, and sequential toggle behavior.

Changes:

  • Added src/tests/components/ToggleDarkMode.test.tsx with 10 unit tests covering all aspects of the ToggleDarkMode component functionality
  • Implemented comprehensive mocking strategy for Zustand store, react-dark-mode-toggle library, and styled-components
  • Tests verify light/dark mode initialization, toggle interactions, store method calls, DOM attribute updates, and component props

@@ -0,0 +1,150 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { render, screen, fireEvent } from '@testing-library/react';
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding import '@testing-library/jest-dom'; for consistency with other test files in the codebase (Navbar.test.tsx and PlaygroundSidebar.test.tsx). While the matchers are globally available via the setup file, explicit imports improve code clarity and align with established patterns in the project.

Suggested change
import { render, screen, fireEvent } from '@testing-library/react';
import { render, screen, fireEvent } from '@testing-library/react';
import '@testing-library/jest-dom';

Copilot uses AI. Check for mistakes.
@kartikrautan
Copy link
Contributor Author

Hi @mttrbrts , just checking in on my PR review. Thanks!

Signed-off-by: kartik <kartikrautan0@gmail.com>
@mttrbrts
Copy link
Member

mttrbrts commented Mar 2, 2026

@kartikrautan can you review the build failures?

Signed-off-by: kartik <kartikrautan0@gmail.com>
@kartikrautan
Copy link
Contributor Author

@kartikrautan can you review the build failures?

Done @mttrbrts thanks for the patience, good to go

@mttrbrts
Copy link
Member

mttrbrts commented Mar 2, 2026

@kartikrautan can you review the build failures?

Done @mttrbrts thanks for the patience, good to go

All of the changes seem to have disappeared?

@kartikrautan
Copy link
Contributor Author

@kartikrautan can you review the build failures?

Done @mttrbrts thanks for the patience, good to go

All of the changes seem to have disappeared?

Oh my bad the ToggleDarkMode component was deleted in a commit that i made, which is already in upstream main. I have added 8 more tests as part of the WebAuthn encryption work

@mttrbrts
Copy link
Member

mttrbrts commented Mar 4, 2026

This new component doesn't appear to be integrated into the app anywhere, and you explain how it is used?

@kartikrautan
Copy link
Contributor Author

kartikrautan commented Mar 7, 2026

This new component doesn't appear to be integrated into the app anywhere, and you explain how it is used?

@mttrbrts The ToggleDarkMode component already exists in the app and is used in the layout to allow users to switch between light and dark themes.
This PR only adds unit tests to improve test coverage and verify its behavior. Adding these tests helps prevent regressions, increases reliability of the theme toggle logic, and strengthens overall code quality without changing existing functionality. Since it’s purely a test addition with no functional impact, it is safe to merge and improves long-term maintainability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Unit Tests For ToggleDarkMode Component

3 participants